package com.enjoyor.soa.traffic.core.ping.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.enjoyor.soa.traffic.core.ping.domain.DevStatusInfo;
import com.enjoyor.soa.traffic.core.ping.mapper.IDevStatusInfoMapper;
import com.enjoyor.soa.traffic.core.ping.service.IDevStatusInfoService;
import com.enjoyor.soa.traffic.frame.logger.IPubLogMapper;
import com.enjoyor.soa.traffic.util.enums.log.LogInfoDic;
import com.enjoyor.soa.traffic.util.helper.LoggerHelper;
import com.enjoyor.soa.traffic.util.helper.TimeHelper;


@Service
@Transactional
@SuppressWarnings("rawtypes")
public class DevStatusInfoService implements IDevStatusInfoService {

    @Autowired
    private IDevStatusInfoMapper devStatusInfoMapper;

    //@Autowired
    //private IPubLogMapper pubLogMapper;

    @Override
	public DevStatusInfo selectDevStatusInfoById(String devId){
	    return devStatusInfoMapper.selectById(devId);
	}
    
    @Override
	public List<DevStatusInfo> selectDevStatusInfoList(String devId, String devStatus, String startTime, String endTime){
    	try {
	    	Map<String,Object> paramT = new HashMap<String ,Object>();
	    	paramT.put("devId", devId);
	    	paramT.put("devStatus", devStatus);
	    	paramT.put("startTime", startTime);
	    	paramT.put("endTime", endTime);
	    	return devStatusInfoMapper.selectDevStatusInfoList(paramT);
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    
    @Override
    public String insertDevStatusInfo(DevStatusInfo devStatusInfo, String personName){
    	try {
	    	// 默认操作记录信息
	        String devId = devStatusInfo.getDevId();
	        devStatusInfo.setUpdateTime(TimeHelper.dateToLongString());
	        devStatusInfoMapper.insert(devStatusInfo);
	        return devId;
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    
    @Override
    public String synDevStatusInfo(DevStatusInfo devStatusInfo){
    	try {
	    	// 默认操作记录信息
	        String devId = devStatusInfo.getDevId();
	        devStatusInfoMapper.insert(devStatusInfo);
	        devStatusInfoMapper.insertDevStatusHis(devStatusInfo);
	        return devId;
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    
    @Override
    public String updateSbjkDevStatus(DevStatusInfo devStatusInfo){
    	try {
	        String devStatus = devStatusInfo.getDevStatus();
	        if(!"1".equals(devStatus)) {
	        	devStatusInfo.setDevStatus("0");
	        }
	        devStatusInfoMapper.updateSbjkDevStatus(devStatusInfo);
	        return devStatusInfo.getDevId();
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }

    @Override
    public String updateDevStatusInfo(DevStatusInfo devStatusInfo, String personName){
    	try {
	    	String devId = devStatusInfo.getDevId();
	    	devStatusInfo.setUpdateTime(TimeHelper.dateToLongString());
	    	devStatusInfoMapper.updateByIdSelective(devStatusInfo);
	        return devId;
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    
    @Override
    public String deleteDevStatusInfo(String devId, String personName){
    	try {
    		devStatusInfoMapper.deleteById(devId);
	        return devId;
    	} catch (Exception e) {
			// TODO: handle exception
			LoggerHelper.LOG.error(e);
			throw e;
		}
    }
    
    
}
